package com.brayan.webapp.service.security;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;

import org.apache.log4j.Logger;

import com.brayan.webapp.model.usermgmt.User;
import com.brayan.webapp.repository.usermgmt.UserRepository;


// The @Stateless annotation eliminates the need for manual transaction demarcation
@Stateless
public class LoginService {

	@Inject
	private Logger log;
	
	@Inject
    private UserRepository repository;

	@Inject
	private Event<User> userEvent;

	public User login(User user) {
		log.info("login " + user.getUsername());

		User rUser = repository.findByCredentials(user.getUsername(), user.getPassword());
		return rUser;
	}
	
	public boolean isAdmin(String userName){
		return repository.isUserAdmin(userName);
	}
}
